]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
inputMethod: Check return value when letting IM handle virtual keys
authorCarlos Garnacho <carlosg@gnome.org>
Tue, 11 Oct 2022 16:24:15 +0000 (18:24 +0200)
committerMarge Bot <marge-bot@gnome.org>
Tue, 18 Oct 2022 19:31:51 +0000 (19:31 +0000)
When propagating keys from the OSK, we usually feed these directly to
the IBusInputContext and let the IM handle the effects of this virtual
key event (which may also include feeding a key event back to us).

But these functions may also return a FALSE value if the key was "let
through" by the IM, which means the ball is in our yard again, and
we are responsible of letting this event get to its destination.

If that happens, just fall through, so the string is committed to
the client as an UTF-8 string, or propagated through keyboard events.

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5930
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2508>

js/misc/inputMethod.js
js/ui/keyboard.js

index cb70f93f7aad2593ea2be3f8af504bbf9defb627..3ee96a7fafe04bc7116e6fe9feaef079a5a98351 100644 (file)
@@ -7,6 +7,8 @@ const Main = imports.ui.main;
 
 Gio._promisify(IBus.Bus.prototype,
     'create_input_context_async', 'create_input_context_async_finish');
+Gio._promisify(IBus.InputContext.prototype,
+    'process_key_event_async', 'process_key_event_async_finish');
 
 var HIDE_PANEL_TIME = 50;
 
@@ -332,10 +334,17 @@ var InputMethod = GObject.registerClass({
         return this._preeditVisible && this._preeditStr !== '' && this._preeditStr !== null;
     }
 
-    handleVirtualKey(keyval) {
-        this._context.process_key_event_async(
-            keyval, 0, 0, -1, null, null);
-        this._context.process_key_event_async(
-            keyval, 0, IBus.ModifierType.RELEASE_MASK, -1, null, null);
+    async handleVirtualKey(keyval) {
+        try {
+            if (!await this._context.process_key_event_async(
+                keyval, 0, 0, -1, null))
+                return false;
+
+            await this._context.process_key_event_async(
+                keyval, 0, IBus.ModifierType.RELEASE_MASK, -1, null);
+            return true;
+        } catch (e) {
+            return false;
+        }
     }
 });
index 28369316e13bbe9ca6ddd78b5331984a4a7b3915..3241571de7e45c7655085371451e26ac27ae5dc6 100644 (file)
@@ -1569,11 +1569,11 @@ var Keyboard = GObject.registerClass({
         }
     }
 
-    _commitAction(keyval, str) {
+    async _commitAction(keyval, str) {
         if (this._modifiers.size === 0 && str !== '' &&
             keyval && this._oskCompletionEnabled) {
-            Main.inputMethod.handleVirtualKey(keyval);
-            return;
+            if (await Main.inputMethod.handleVirtualKey(keyval))
+                return;
         }
 
         if (str === '' || !Main.inputMethod.currentFocus ||